package com.game.animation;

import android.graphics.Canvas;
import android.graphics.Color;

import com.game.utils.AnimationInterpolatorUtil;

/**
 * 条纹交错
 * 矩形相交
 * @author Administrator
 *
 */
public class AnimationGradualchangeRefCross extends AnimationGradualchange {
	int crossType=1;   //1 横纹 2竖纹
 	int crossCount=5;//单边条纹数
	float span=0;//每条间的间距
	
	public AnimationGradualchangeRefCross(AnimationObject object,AnimationGradualchangeCallBack callBack,int crossCount,int crossType,float time){
		super(object,callBack,time);
		this.crossCount=crossCount;
		this.crossType=crossType;
		if(crossType==1){
			span=object.getHeight()/crossCount/2;
		}else{
			span=object.getWidth()/crossCount/2;
		}
	}
	
	@Override
	public void step(Canvas canvas,float perc) {
		float x = object.getPostX();
		float y = object.getPostY();
		float width = object.getWidth();
		float height = object.getHeight();
		switch (crossType) {
		case 1:{  //横
			for(int i=0;i<crossCount*2;i++){
				if(i%2!=0){
//					canvas.clipRect(x+(1-perc)*width,y+span*i,x+width,y+span*(i+1));
					canvas.drawRect(x+(1-perc)*width,y+span*i,x+width,y+span*(i+1)+1,paint);
				}else{
//					canvas.clipRect(x,y+span*i,x+perc*width,y+span*(i+1));
					canvas.drawRect(x,y+span*i,x+perc*width,y+span*(i+1)+1,paint);
				}
			}
			break;
		}
		case 2:{//竖
			for(int i=0;i<crossCount*2;i++){
				if(i%2!=0){
					canvas.drawRect(x+span*i ,y+(1-perc)*height,x+span*(i+1)+1,y+height,paint);
				}else{
					canvas.drawRect(x+span*i,y,x+span*(i+1)+1,y+perc*height,paint);
				}
			}
			break;
		}
		default:
			break;
		}
	}

	public int getSpeedType() {
		return speedType;
	}

	public void setSpeedType(int speedType) {
		this.speedType = speedType;
	}
	
}

